/**********************
发起填报
* */
<template>
  <basic-container>
    <el-row>
      <targetExaminHead :sign="{ e: true}" />
    </el-row>
    <el-row v-if="!isFillIn">
      <el-row style="margin:25px 0 0 0 ;">
        <div :height="searchheight">
          <span
            style="float:right;margin-top: -30px;cursor: pointer;"
            @click="searchchangeadvanced"
          >
            {{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
            <i
              :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
            />
          </span>
          <div v-show="searchadvanced">
            <el-form
              :inline="true"
              :model="searchForm"
              @keyup.enter.native="getDataList()"
              class="form-inline"
            >
              <el-form-item label="考核对象">
                <el-input v-model="searchForm.assessRealName" placeholder="考核对象" :clearable="true"></el-input>
              </el-form-item>
              <el-form-item label="考核名称">
                <el-input v-model="searchForm.name" placeholder="考核名称" :clearable="true"></el-input>
              </el-form-item>
              <el-form-item label="考核周期">
                <selectSearch @getDataByPerid="getDataByPerid"></selectSearch>
              </el-form-item>
              <el-form-item>
                <el-button
                  icon="el-icon-search"
                  type="primary"
                  class="marginLeft"
                  @click="getDataList(1)"
                >检索</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </el-row>
      <el-row>
        <div style="height: 50px; border-bottom: 1px solid #b0bde2">
          <div class="pull-right">
            <el-button type="primary" :disabled="canSub" @click="batchInitiation">批量发起</el-button>
          </div>
        </div>
      </el-row>
      <div style="margin:20px 0 0 0 ">
        <span>指标考核&nbsp;&nbsp;</span>
        <el-radio-group v-model="choosePerOrDept" @change="choosePerOrDeptChange">
          <el-radio :label="0">人员</el-radio>
          <el-radio :label="1">机构</el-radio>
        </el-radio-group>
      </div>
      <el-row>
        <el-table
          style="width: 100%;margin-top:20px"
          :data="dataList"
          border
          stripe
          header-align="center"
          v-loading="dataListLoading"
          @selection-change="handleSelect"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column type="index" header-align="center" align="center" label="序号" width="55"></el-table-column>
          <el-table-column prop="assessUserName" align="center" label="员工编号" show-overflow-tooltip v-if="!choosePerOrDept"></el-table-column>
          <el-table-column prop="assessRealName" align="center" label="考核对象" show-overflow-tooltip v-if="!choosePerOrDept">
            <template slot-scope="scope">
              <span
                style="color:#0e258c;cursor:pointer"
                @click="startFillIn(scope.row)"
              >{{scope.row.assessRealName}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="assessDeptName" align="center" label="考核对象" show-overflow-tooltip v-else >
            <template slot-scope="scope">
              <span
                style="color:#0e258c;cursor:pointer"
                @click="startFillIn(scope.row)"
              >{{scope.row.assessDeptName}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="assessDeptName" align="center" label="部门" show-overflow-tooltip v-if="!choosePerOrDept"></el-table-column>
          <el-table-column prop="itemNum" align="center" label="指标数量" show-overflow-tooltip></el-table-column>
          <el-table-column prop="name" align="center" label="考核名称" show-overflow-tooltip></el-table-column>
          <el-table-column prop="period" align="center" label="考核周期" show-overflow-tooltip></el-table-column>
          <el-table-column prop="weight" align="center" label="权重" show-overflow-tooltip>
            <template slot-scope="scope">
              <span :class="scope.row.weight==100?'weightColor':'weightRed'">{{scope.row.weight}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="state" align="center" label="状态" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.state | transTargetState}}</span>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageData.pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageData.pageSize"
            :total="pageData.totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          ></el-pagination>
        </div>
      </el-row>
    </el-row>
    <el-row v-if="isFillIn">
      <el-table
        style="width: 100%;margin-top:20px"
        :data="detailDataList"
        border
        v-if="isFillIn"
        show-summary
        stripe
        header-align="center"
        v-loading="dataListLoading"
      >
        <el-table-column type="index" align="center" label="序号" width="55"></el-table-column>
        <el-table-column prop="sjbt" align="center" label="员工编号" show-overflow-tooltip></el-table-column>
        <el-table-column prop="assessRealName" align="center" label="姓名" show-overflow-tooltip></el-table-column>
        <el-table-column prop="assessDeptName" align="center" label="部门" show-overflow-tooltip></el-table-column>
        <el-table-column prop="type" align="center" label="指标类别" show-overflow-tooltip></el-table-column>
        <el-table-column prop="name" align="center" label="指标名称" show-overflow-tooltip></el-table-column>
        <el-table-column prop="weight" align="center" label="权重" show-overflow-tooltip></el-table-column>
        <el-table-column prop="formula" align="center" label="计算公式" show-overflow-tooltip></el-table-column>
        <el-table-column prop="targetValue" align="center" label="目标值" show-overflow-tooltip></el-table-column>
        <el-table-column prop="unit" align="center" label="单位" show-overflow-tooltip></el-table-column>
        <el-table-column prop="finishValue" align="center" label="填报值" show-overflow-tooltip></el-table-column>
        <el-table-column prop="score" align="center" label="得分" show-overflow-tooltip></el-table-column>
        <el-table-column prop="finalScore" align="center" label="修改得分" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-input
              @change="((val)=>{
              detailScoreChange(scope.row)})"
              v-model.number="scope.row.finalScore"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="provideRealName" align="center" label="数据提供部门" show-overflow-tooltip></el-table-column>
      </el-table>
      <el-row style="margin:10px;text-align:right">
        <el-button type="success" @click="isFillIn=false">确定</el-button>
        <el-button type="primary" @click="isFillIn=false">返回</el-button>
      </el-row>
    </el-row>
    <examinView v-if="examinVisible" ref="examinNode" @closeDialog="closeDialog1" />
  </basic-container>
</template>

<script>
import targetExaminHead from "@/views/dailyExamine/components/targetExaminHead"; //状态头
import { examineList } from "@/api/dailyExamine/targetExamine/createAssessment"; //接口api
import { batchStart } from "@/api/dailyExamine/targetExamine/InitiateFilling";
import examinView from "@/views/dailyExamine/targetExamine/indicatorView/examinView";
import selectSearch from "@/views/dailyExamine/components/select-search.vue"; //流程组件

export default {
  data() {
    return {
      examinVisible: false, //

      choosePerOrDept: 0,
      canSub: true,
      detailDataList: [],
      isFillIn: false,
      searchheight: "0", //搜索组件的高度
      searchadvanced: true, //搜索的显隐
      searchForm: {}, //搜索对象
      addVisible: false, //
      dataListLoading: false, //表格是否加载
      dataList: [], //表格数组
      multipleSelection: [], //勾选数据
      pageData: {
        //分页对象
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0
      }
    };
  },
  components: {
    examinView,
    targetExaminHead, //状态头
    selectSearch
  },
  watch: {
    multipleSelection: {
      handler(val) {
        if (val.length == 0) {
          this.canSub = true;
        } else {
          this.canSub = false;
        }
      }
    }
  },
  created() {
    this.getDataList();
  },
  methods: {
    choosePerOrDeptChange(val) {
      this.searchForm = {};
      this.dataList = [] ;
      this.getDataList();
    },
    handleSelect(val) {
      this.multipleSelection = val;
    },
    // 批量发起
    batchInitiation() {
      this.$confirm(`是否批量发起选中数据`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(result => {
          let ids = this.multipleSelection.map(it => {
            return it.id;
          });
          batchStart(ids.toString())
            .then(r => {
              if (r.data.code == 0) {
                this.$message.success("发起成功");
                this.getDataList();
              }
            })
            .catch(err => {});
        })
        .catch(err => {
          console.log("取消");
        });
    },
    closeDialog1() {
      this.examinVisible = false;
    },
    // 点击名字填报
    startFillIn(row) {
      // this.isFillIn = true;
      this.examinVisible = true;
      this.$nextTick(() => {
        this.$refs.examinNode.init(row);
      });
    },
    // 查询条件的展开关闭
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "auto";
      }
    },
    // 查询列表
    getDataList() {
      ////
        this.dataListLoading = true ;
        examineList(
        Object.assign(
          {
            current: this.pageData.pageIndex,
            size: this.pageData.pageSize,
            type: this.choosePerOrDept
          },
          this.searchForm
        ),
        5
      )
        .then(r => {
          if (r.data.code == 0) {
            this.dataListLoading = false ;
            this.dataList = r.data.data.records;
            this.pageData.totalPage = r.data.data.total;
          }
        })
        .catch(err => {});
    },
    // 条数变化
    sizeChangeHandle(val) {
      this.pageData.pageSize = val;
      this.getDataList();
    },
    // 页码分页变化
    currentChangeHandle(val) {
      this.pageData.pageIndex = val;
      this.getDataList();
    },
      //选择周期执行搜索功能
      getDataByPerid(period){
          this.searchForm.period = period ;
          this.getDataList() ;
      }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-select .el-select__tags {
  overflow: auto !important;
}
::v-deep.el-tag.el-tag--info {
  margin: 5px;
  border: 1px solid green;
}
.weightRed {
   color: rgba(255, 0, 0, 0.726);
 }

</style>
